package com.maijinjie.common.builder.template.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.maijinjie.common.bean.Pagination;
import com.maijinjie.common.bean.StatusBean;
import com.maijinjie.common.builder.template.bean.MyName_Bean;
import com.maijinjie.common.builder.template.dao.MyName_Mapper;
import com.maijinjie.common.builder.template.fields.MyName_Fields;
import com.maijinjie.common.builder.template.service.MyName_Service;
import com.maijinjie.common.service.impl.BaseServiceImpl;

/**
 * MyName_ServiceImpl
 * @author 作者_
 **/
@Service("myName_Service")
public class MyName_ServiceImpl extends BaseServiceImpl implements MyName_Service{
	@Resource
	MyName_Mapper myName_Mapper;
	
	@Override
	public MyName_Bean getBeanById(Integer id) throws Exception{
		if(null==id || 0>=id){
			return null;
		} else {
			return (MyName_Bean) getBeanById(myName_Mapper, id);
		}
	}
	@Override
	public int count(Map<String, Object> params) throws Exception {
		return myName_Mapper.count(params);
	}
	@Override
	public List<MyName_Bean> list(Map<String, Object> params) throws Exception {
		return (List<MyName_Bean>) myName_Mapper.list(params);
	}
	@Override
	public StatusBean save(MyName_Bean bean, String createBy, Integer createUserId) throws Exception {
		Date currDate = new Date();
		//TODO 处理业务
		
		if(0<myName_Mapper.save(bean)){
			return success("操作成功！");
		}
		return error("操作失败！");
	}
	@Override
	public StatusBean update(MyName_Bean bean, String createBy, Integer createUserId) throws Exception {
		if(null!=bean){
			Date currDate = new Date();
			HashMap<String, Object> params = new HashMap<String, Object>();
			//TODO 处理业务
			
			if(myName_Mapper.update(params)){
				return success("操作成功！");
			}
		}
		return error("操作失败！");
	}
	@Override
	public StatusBean deleteById(Integer id) throws Exception {
		if(null!=id && 0<id){
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put(MyName_Fields.idName_.toString(), id);
			if(myName_Mapper.delete(params)){
				return success("操作成功！");
			}
		}
		return error("操作失败！");
	}
	@Override
	public Pagination<MyName_Bean> list(Pagination<MyName_Bean> pagination) throws Exception {
		return (Pagination<MyName_Bean>) getPagination(myName_Mapper, pagination);
	}
	@Override
	public StatusBean batchDelete(String ids) throws Exception {
		if(null!=ids && !"".equals(ids.trim())) {
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put(MyName_Fields.idName_.toString(), ids);
			if(myName_Mapper.batchDelete(params)){
				return success("操作成功！");
			}
		}
		return error("操作失败！");
	}
	@Override
	public List<MyName_Bean> listAll() throws Exception {
		return (List<MyName_Bean>) myName_Mapper.list(null);
	}
}